// ignore_for_file: file_names, must_be_immutable, constant_identifier_names, slash_for_doc_comments, avoid_unnecessary_containers, prefer_const_constructors, unnecessary_cast, sized_box_for_whitespace, prefer_function_declarations_over_variables, overridden_fields, annotate_overrides, prefer_const_literals_to_create_immutables, unnecessary_null_comparison, deprecated_member_use

import 'package:flutter/cupertino.dart';
import 'package:myuis/theme/MyuisTheme.dart';

///傻瓜式获取上下文
BuildContext getContext({BuildContext? context}) {
  if (context != null) {
    return context;
  }
  BuildContext? ctl = MyuisManager().delegate?.myuisDelegate_getContext();
  assert(ctl != null, "MyuisManager delegate没有赋值");
  return ctl!;
}

///傻瓜式获取主题
MyuisTheme getTheme() {
  MyuisTheme? theme = MyuisManager().delegate?.myuisDelegate_theme();
  if (theme == null) {
    return MyuisManager().defaultTheme;
  }
  return theme;
}

class MyuisManager {
  // 单例公开访问点
  factory MyuisManager() => _sharedInstance();

  // 静态、同步、私有访问点
  static MyuisManager _sharedInstance() {
    return _instance;
  }

  // 静态私有成员，没有初始化
  static final MyuisManager _instance = MyuisManager._();

  // 私有构造函数
  MyuisManager._() {
    // 具体初始化代码
  }

  ///代理对象
  MyuisDelegate? delegate;

  ///默认主题
  MyuisTheme defaultTheme = MyuisTheme();
}

abstract class MyuisDelegate {
  BuildContext myuisDelegate_getContext();

  MyuisTheme? myuisDelegate_theme();
}
